//
//  SNFoodMealTableViewCell.m
//  project
//
//  Created by 黄建华 on 2018/11/14.
//  Copyright © 2018年 黄建华. All rights reserved.
//

#import "SNFoodMealTableViewCell.h"

@implementation SNFoodMealTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    
    return self;
}

- (void)createView {
    _mealCount = [[UIButton alloc] init];
    [self addSubview:_mealCount];
    
    _foodsLabel = [[UILabel alloc] init];
    [self addSubview:_foodsLabel];
    
    _calorsLabel = [[UILabel alloc] init];
    [self addSubview:_calorsLabel];
    
    _line = [[UIView alloc] init];
    [self addSubview:_line];
}

- (void)updateCellWithModel:(FoodEatModel *)model
{
    // 用餐图标
    _mealCount.frame = SNFRAME(20,15, 40, 40);
    _mealCount.layer.cornerRadius = 20.0;
    _mealCount.layer.masksToBounds = YES;
    _mealCount.backgroundColor = FOODCOLOR;
    [_mealCount setTitle:StrByInt(model.serial+1) forState:UIControlStateNormal];
    
    NSArray *array = model.foodListArray;
    NSMutableString *foodString = [NSMutableString string];
    for (int i = 0; i <array.count; i++) {
        NSString *name = [array objectAtIndex:i][@"name"];
        [foodString appendString:name];
        if (i<array.count -1) {
            [foodString appendString:@"/"];
        }
    }
    _foodsLabel.frame = SNFRAME(70,0,HHHWIDTH - 70-95,70);
    _foodsLabel.text = foodString;
    _foodsLabel.font = SNFONT(SNFITFONTSIZE(15));
    _foodsLabel.numberOfLines = 4;
    _foodsLabel.textAlignment = NSTextAlignmentCenter;
    
    _calorsLabel.frame = SNFRAME(HHHWIDTH -95,25, 90, 20);
    _calorsLabel.text = [NSString stringWithFormat:@"%.0f %@",model.caloryTotal,SN_Text(@"大卡")];
    _calorsLabel.textAlignment = NSTextAlignmentRight;
    _calorsLabel.font = SNFONT(13.0);
    _calorsLabel.textColor = FOODCOLOR;
    [_calorsLabel setAttributedText:[SN_PublicClass labelSelfText:_calorsLabel.text withChangeText:SN_Text(@"大卡") withFontsize:14.0 withChangeColor:[UIColor blackColor]]];
    
    _line.frame = SNFRAME(0, 69, HHHWIDTH,0.5);
    _line.backgroundColor = SNCOLORGRAYLINE;
}

@end
